<?php

session_start();
$pathinfo = pathinfo(__FILE__);
preg_match('/.+(?=wp-content)/', $pathinfo['dirname'], $match);
$pathNeeded = preg_replace('/\ /', '/', $match[0]);
require_once($pathNeeded . 'wp-load.php'); //refer to wp-load to use instruction

$user = new User();


$data['first_name'] = $_REQUEST['name'];
$data['last_name'] = $_REQUEST['lastname'];
$data['password'] = $_REQUEST['password'];
$data['email'] = $_REQUEST['email'];
$data['city'] = $_REQUEST['city'];
$data['state'] = $_POST['state'];
$data['country'] = $_POST['country'];
$data['postcode'] = $_POST['postcode'];
$checkemail = User::checkUserNameByEmail($_REQUEST['email']); //check if email is existed
if ($checkemail == false) {//if this email is not existed
    $id_user_register = $user->add_user($data);
    $data['id_user_register'] = $id_user_register;
    MailHelper::sendmailRegister($data);
    $suscessful = 1;
} else {
    if ($checkemail) {
        $suscessful = 3;
    }
}
echo $suscessful;